package com.temp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.temp.entity.Route;
import com.temp.vo.RouteVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RouteMapper extends BaseMapper<Route> {

    @Select("SELECT r.id, r.parent_id, r.redirect, r.path, r.name, r.component, r.title, r.icon, r.sort, r.hidden, r.status, r.created_at, r.updated_at " +
            "FROM route r " +
            "JOIN route_role rr ON r.id = rr.route_id " +
            "JOIN user u ON rr.role_id = u.role_id " +
            "JOIN role ro ON u.role_id = ro.id " +
            "WHERE u.id = #{userId} " +
            "  AND r.status = 1 " +
            "  AND ro.status = 1 " +
            "ORDER BY r.sort ASC")
    List<RouteVO> findAuthorizedRoutesByUserId(@Param("userId") Long userId);

    @Select("SELECT r.* " +
            "FROM route r " +
            "ORDER BY r.sort ASC")
    List<RouteVO> findAllAuthorizedRoutes();
}
